

// 加载菜单
function refreshMenu(row){
	$.post(frame.fullUrl("/base/menu/query.json"), function(menus) {
		if(menus){
			$('#tt').tree("loadData",menus);
			$.post("./getrolemenu.json",
					row,
			 		function(rolemenus) {
						if (rolemenus) {
							for (var i = 0; i < rolemenus.length; i++) {
								var node = $('#tt').tree('find', rolemenus[i].menuCode);
								if ($('#tt').tree("isLeaf", node.target))
									$('#tt').tree("check", node.target);
							}
						}
					}
				);
		}
	});
}

var selected=-1;
function clickRole(index, row){
	if(selected != index){
		selected = index;
		refreshMenu(row);
	}
}

function click_save(){
	var ids = "";
	var nodes = $('#tt').tree('getChecked', 'indeterminate');
	for(var i=0;i<nodes.length;i++){
		ids+=nodes[i].id+",";
	}
	nodes = $('#tt').tree('getChecked');
	for(var i=0;i<nodes.length;i++){
		ids+=nodes[i].id+",";
	}
	var row = $("#dg").datagrid("getSelected");
	row.menuIds = ids;
	$.post("./saverolemenu.json",row);
}



